package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.server.mapper.SbackMapper;
import com.xxxx.server.pojo.Admin;
import com.xxxx.server.pojo.RespPageBean;
import com.xxxx.server.pojo.Sback;
import com.xxxx.server.service.ISbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 学生返校申请 服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2022-06-02
 */
@Service
public class SbackServiceImpl extends ServiceImpl<SbackMapper, Sback> implements ISbackService {

    @Autowired
    private SbackMapper sbackMapper;

    @Override
    public List<Sback> getSbackBySBId() {
        return sbackMapper.getSbackBySBid(((Admin) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId());
    }

    @Override
    public RespPageBean getSbackByPage(Integer currentPage, Integer size, Sback sback, String[] beginDateScope) {
        Page<Sback> page = new Page<>(currentPage,size);
        IPage<Sback> SbackByPage = sbackMapper.getSbackByPage(page, sback, beginDateScope);
        RespPageBean respPageBean = new RespPageBean(SbackByPage.getTotal(), SbackByPage.getRecords());
        return respPageBean;
    }

    @Override
    public List<Sback> getSback(Integer id) {
        return sbackMapper.getSback(id);
    }
}